package com.zmzncs.shop.module.system.service.impl;

import org.springframework.beans.BeanUtils;
import com.zmzncs.shop.module.system.pojo.user.*;
import com.zmzncs.shop.module.system.mapper.UserMapper;
import com.zmzncs.shop.module.system.service.UserService;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.core.metadata.IPage;
import org.springframework.beans.factory.annotation.Autowired;


/**
 * <p>
 *  服务实现类
 * </p>
 *
 * @author 任建波
 * @since 2020-12-31
 */
@Service
public class UserServiceImpl extends ServiceImpl<UserMapper, User> implements UserService {

    @Autowired
    private UserMapper userMapper;

    @Override
    public IPage<UserDTO> page(UserSearchForm form){
        IPage<UserDTO> iPage = userMapper.list(form.getPage());

        return iPage;
    }

    @Override
    public void add(UserAddForm form){
        User user = new User();
        BeanUtils.copyProperties(form, user);

        userMapper.insert(user);
    }

    @Override
    public void delete(Long id){
        User user = new User();
        user.setId(id);
//        user.isDeleted(1);

        userMapper.updateById(user);
    }

    @Override
    public void update(UserUpdateForm form){
        User user = new User();
        BeanUtils.copyProperties(form, user);

        userMapper.updateById(user);
    }

    @Override
    public UserDTO getById(Long id){
        UserDTO userDTO = userMapper.getById(id);

        return userDTO;
    }

}
